1. What does argc represent in a C program that uses command-line arguments?
Correct Answer: (C) Argument count
2. What is stored in argv[0] when a C program is executed with command-line arguments?
Correct Answer: (D) The program’s name
3. How would you compile and run a C program that uses command-line arguments?
Correct Answer: (C) gcc program.c -o program; ./program arg1 arg2
4. If a program is executed as ./program arg1 arg2 arg3, what will be the value of argc?
Correct Answer: (C) 4
5. In the command-line argument example provided, what does the atoi function do?
Correct Answer: (B) Converts a string to an integer
6. Which of the following commands is used to create a new directory in the command line?
Correct Answer: (B) MD
7. In the context of command-line arguments, which of the following is correct for char *argv[]?
Correct Answer: (C) It is an array of pointers to strings representing arguments.
8. What will be the output of the following program if executed as ./program 10 20?
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int num1 = atoi(argv[1]);
int num2 = atoi(argv[2]);
int sum = num1 + num2;
printf("Sum: %d\n", sum);
return 0;
}
Correct Answer: (B) Sum: 30
9. Which of the following commands is used to clear the terminal screen?
Correct Answer: (B) CLS
10. In a program using command-line arguments, what does the first argument (argv[0]) always contain?
Correct Answer: (B) The program’s name